package book.service.impl;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import book.dao.CategoryDao;
import book.dao.impl.CategoryDaoImpl;
import book.entity.Category;
import book.service.CategoryService;
import book.utils.JdbcUtils;

public class CategoryServiceImpl implements CategoryService {

	CategoryDao categoryDao = new CategoryDaoImpl();

	@Override
	public Category getCategory(Integer categoryId) throws SQLException {

		Connection connection = JdbcUtils.getConnection();

		String sql = "SELECT category_id as categoryId,category_name as categoryName FROM category WHERE category_id=?";

		Category category = categoryDao.getCategory(connection, sql, Category.class, categoryId);
		return category;
	}

	@Override
	public List<Category> getCategoryList() throws SQLException {
	
		
		Connection connection = JdbcUtils.getConnection();
		
		String sql = "SELECT category_id as categoryId,category_name as categoryName FROM category";

		
		List<Category> categoryList = categoryDao.getCategoryList(connection, sql,Category.class);
		
		
		return categoryList;
	}

}
